package com.atguigu.fink.chapter01.timeattr;

import com.atguigu.fink.bean.WaterSensor;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

import static org.apache.flink.table.api.Expressions.$;

/**
 * @Author lzc
 * @Date 2022/11/28 15:09
 */
public class Flink01_TableApi_Time_Process {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 2000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);
        DataStreamSource<WaterSensor> stream = env.fromElements(
            new WaterSensor("s1", 1L, 10),
            new WaterSensor("s1", 2L, 10),
            new WaterSensor("s2", 3L, 20),
            new WaterSensor("s1", 4L, 30),
            new WaterSensor("s1", 5L, 40),
            new WaterSensor("s1", 6L, 50)
        );
        
        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
       
        // 1. 流转成表的时候添加处理时间字段
//        Table table = tEnv.fromDataStream(stream, $("id"), $("ts"), $("vc"), $("pt").proctime());
        Table table = tEnv.fromDataStream(stream, $("id"), $("ts"), $("pt").proctime(), $("vc"));
        table.printSchema();
        table.execute().print();
        
    }
}
